package zhzzofbl;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import zhzz.AllIllnessOfZH;
import zhzz.SingleDataofzhzz;

import com.example.animaldoctor03.JBXQ;
import com.example.animaldoctor03.R;
import com.example.animaldoctor03.ZhengDuanFF;

import commonClass.ADAQueryClinicalSymptomsKeyByDiseaseIDAction;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import bingliandshuju.BingLi3;
import bingliandshuju.SingleDataofAll;
import Modle.disease.ClinicalSymptomsKey;
import Modle.disease.Symptoms;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class bi2ofzh extends Activity {

	
	
	private String nameofBL2 = "";
	private String GLofBL2 ;
	private Button buttonofbinli5 = null, buttonofcheckjibingdetail = null;
	private Button  buttonofbingli2toagain = null ,buttonofBL2F = null;
	private ListView listofbingli2 = null;
	private TextView textofBL2 = null;
	

	private List<Object> listofBL2getinformation = new ArrayList<Object>();
	private List<Object> listofbi2getbasic = new ArrayList<Object>();
	private String animalIDofBL2 = "";
	private ArrayList<Object>resultListofBL2 = null;
	
	
	private  void initElemofBL2 (){
		setContentView(R.layout.bingli2);
		buttonofBL2F = (Button)findViewById(R.id.buttonofBL2F);
		listofbingli2 = (ListView) findViewById(R.id.listofbingli2);
		textofBL2 = (TextView)findViewById(R.id.textviewofbinli);
		buttonofbingli2toagain = (Button) findViewById(R.id.buttonofbingli21);


		buttonofcheckjibingdetail = (Button) findViewById(R.id.buttonofbingli1);
		buttonofbinli5 = (Button) findViewById(R.id.buttonofbingli23);
		buttonofcheckjibingdetail.setOnClickListener(new listenercheckdetail());
		buttonofBL2F.setOnClickListener(new listenerofBL2F());

	
		buttonofbingli2toagain.setOnClickListener(new listenerofbingli2toagain());
	}
	private void getInformationofBL2 (){
		
		SingleDataofAll singleDataofBL2 = SingleDataofAll.getInstance();
		listofBL2getinformation = singleDataofBL2.getListinformation();
		
		SingleDataofzhzz singleDataofzhzzofbi2 = SingleDataofzhzz.getInstance();
		listofbi2getbasic = singleDataofzhzzofbi2.getListinformation();
		
		
	}
	private void getInformationfromupofBL2(){
		Intent intentofBL2 = getIntent();
		Bundle bundleofBL2 = intentofBL2.getExtras();
		ClinicalSymptomsKey CofBL2 = (ClinicalSymptomsKey) bundleofBL2.getSerializable("shuju");
		animalIDofBL2 = CofBL2.getDiseaseID();
		nameofBL2 = CofBL2.getDiseaseName();
		DecimalFormat formatofBL2 = new DecimalFormat("#.0000");
		GLofBL2 =formatofBL2.format( CofBL2.getDiseaseProbability()) ;
		Message msgofBL2 = new Message();
		msgofBL2.what = 1;
		handleofbinli.sendMessage(msgofBL2);
		
	}
	private ArrayList<Object> assemblyofBL2() {

		getInformationfromupofBL2();
		ArrayList<Object> list = new ArrayList<Object>();

		list.add(animalIDofBL2);
		// Integer i = new Integer(10);
		// list.add(i);

		return list;
	}
	private void bindingofBL2(final ArrayList<Object> list){
		
	try{	
		getInformationofBL2();
		if(list.size() > 0){
			Log.v("22222", "bushikongzhi");
		}
		List<String> listofoldIdsofBL2 = new ArrayList<String>();
		
		for(int i = 0 ; i < listofbi2getbasic.size(); i ++ ){
			Symptoms ctext = (Symptoms) listofbi2getbasic.get(i);
			listofoldIdsofBL2.add(ctext.getSymptomsID());
			
		}
		
		for(int i = 0 ; i < listofBL2getinformation.size(); i ++ ){
			
			
			Symptoms ctextofBL2 = (Symptoms) listofBL2getinformation.get(i);
			
			listofoldIdsofBL2.add(ctextofBL2.getSymptomsID());
			
		}
		
		
		
		
		List<Object> listofZZhuanofBL2 = new ArrayList<Object>();
	
		List<Object> listofBL2QC = new ArrayList<Object>();
		
		for(int j = 0 ; j < list.size() ; j ++){
			
			ClinicalSymptomsKey cetext1ofBL2 = (ClinicalSymptomsKey) list.get(j);
			String sofctext1ofBL2 = cetext1ofBL2.getClinicalSymptomsKeyID();
			for( String s : listofoldIdsofBL2){
				if(sofctext1ofBL2.equals(s)){
				
					listofBL2QC.add(cetext1ofBL2);
			}
			
		}
		}

			
		for(int i = 0 ; i < list.size(); i++ ){
			

			int jishuofBL2 = 0;
			ClinicalSymptomsKey ctext2ofBL2 = (ClinicalSymptomsKey) list.get(i);
			String sofctext2ofBL2 = ctext2ofBL2.getClinicalSymptomsKeyID();
			for(String s : listofoldIdsofBL2){
				if(!sofctext2ofBL2.equals(s)){
					jishuofBL2 ++;
					
				}
				if(jishuofBL2 == listofoldIdsofBL2.size()){
					listofZZhuanofBL2.add(ctext2ofBL2);
				}
				
			}
		}
		
			
			String[] resultofBL2 = new String[listofZZhuanofBL2.size()];
			// list.toArray(new String[list.size()]);
			for (int i = 0; i < listofZZhuanofBL2.size(); i++) {
				
				
				//haiyouwenti
				resultofBL2[i] =( (ClinicalSymptomsKey)listofZZhuanofBL2.get(i)).getClinicalSymptomsKey() ;
			}
			ArrayAdapter<String> arrayAdapterofBL2 = new  ArrayAdapter<>(this, android.R.layout.simple_list_item_multiple_choice ,resultofBL2 );
			listofbingli2.setAdapter(arrayAdapterofBL2);
			buttonofbinli5.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					 ArrayList<Object> listofnextofBL2 = new ArrayList <Object>();
					 List<String> listofb2ofzhofid = new ArrayList<String>();
						
						for(long ids :listofbingli2.getCheckItemIds() ){
							
						int i = (int) ids;
							
							listofnextofBL2.add((ClinicalSymptomsKey)list.get(i));
							listofb2ofzhofid.add(((ClinicalSymptomsKey)list.get(i)).getClinicalSymptomsKeyID());
							//System.out.println("#################" + ids);
						}
						
						//把数据储存好
						SingleDataofAll singleDataofAllofBL2 = SingleDataofAll.getInstance();
						singleDataofAllofBL2.setListinformation(listofnextofBL2);
						singleDataofAllofBL2.setidinformation(listofb2ofzhofid);
						List<String> listofb2ofzh = new ArrayList<String>();
						for(int e = 0 ; e < listofnextofBL2.size() ; e++){
							listofb2ofzh.add(((ClinicalSymptomsKey)listofnextofBL2.get(e)).getClinicalSymptomsKey());
							
						}
						singleDataofAllofBL2.setstringinformatin(listofb2ofzh);
						try{
							Intent intentofbinlicheckall = new Intent(bi2ofzh.this,
									Choiceofzh.class);
							startActivity(intentofbinlicheckall);
							finish();
							}catch(RuntimeException e){
								android.app.AlertDialog.Builder builderofBL2oftoYXZZ = new AlertDialog.Builder(bi2ofzh.this);
								builderofBL2oftoYXZZ.setMessage("不能使用该功能 ,请重试或者使用其他功能");
								builderofBL2oftoYXZZ.create().show();
							}
				}
			});
	}catch(NullPointerException e){
		android.app.AlertDialog.Builder builderofBL2 = new AlertDialog.Builder(bi2ofzh.this);
		builderofBL2.setMessage("无数据, jjjjjj");
		builderofBL2.create().show();
	}
		}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		

		initElemofBL2();
		ArrayList<Object> parasListofBL2 = assemblyofBL2();
		
		final ArrayList<Object> resultListTofBL2 = null;
		
		ADAQueryClinicalSymptomsKeyByDiseaseIDAction iActionofBL2 = new ADAQueryClinicalSymptomsKeyByDiseaseIDAction();
		FunctionDispatcher functionDispacherofBL2 = new FunctionDispatcher();
		
		functionDispacherofBL2.exceute(RemoteActionsName.QueryClinicalSymptomsKeyByDiseaseIDAction, parasListofBL2, iActionofBL2, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
				try{

				Log.v("ZhengZhuangFZ2", "post:" + resultList.toString());
				bi2ofzh.this.resultListofBL2 = resultList;
				bindingofBL2(resultListofBL2);
				}catch(NullPointerException e){
					android.app.AlertDialog.Builder builderofBL2off = new AlertDialog.Builder(bi2ofzh.this);
					builderofBL2off.setMessage("返回值为空 , 请用其他功能ssssss");
					builderofBL2off.create().show();
				}
			}
		} ,this);

	}

	
	class listenerofBL2F implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			try{
			Intent intentofBL2F = new Intent(bi2ofzh.this , ZhengDuanFF.class);
			startActivity(intentofBL2F);
			finish();
			}catch(RuntimeException e){
				android.app.AlertDialog.Builder builderofBL2ofF = new AlertDialog.Builder(bi2ofzh.this);
				builderofBL2ofF.setMessage("不能使用该功能 ,请重试或者使用其他功能");
				builderofBL2ofF.create().show();
			}
		}
		
		
	}
	class listenerofbingli2toagain implements OnClickListener {

		@Override
		public void onClick(View v) {
			
			try{
			Intent intentofbingli2toagain = new Intent(bi2ofzh.this,
					AllIllnessOfZH.class);
		/*	intentofbingli2toagain.putExtras(bundleofagainofBL3);*/
			startActivity(intentofbingli2toagain);
			finish();
			}catch(RuntimeException e){
				android.app.AlertDialog.Builder builderofBL2oftoA = new AlertDialog.Builder(bi2ofzh.this);
				builderofBL2oftoA.setMessage("不能使用该功能 ,请重试或者使用其他功能");
				builderofBL2oftoA.create().show();
			}
		}

	}


	class listenercheckdetail implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			try{
			Bundle bundleofBL2 = new Bundle();
			bundleofBL2.putString("shuju", animalIDofBL2);
			Intent intentofbinli2checkdetail = new Intent(bi2ofzh.this,
					JBXQ.class);
			intentofbinli2checkdetail.putExtras(bundleofBL2);
			startActivity(intentofbinli2checkdetail);
			finish();
			}catch(RuntimeException e){
				android.app.AlertDialog.Builder builderofBL2oftoJBXQ = new AlertDialog.Builder(bi2ofzh.this);
				builderofBL2oftoJBXQ.setMessage("不能使用该功能 ,请重试或者使用其他功能");
				builderofBL2oftoJBXQ.create().show();
			}
		}

	}



	
	  public Handler handleofbinli = new Handler() {
		
		  public void  handleMessage(Message msg) {
	  
		  if(msg.what == 1){
			  
		  
			  	textofBL2.setText("病名：" + nameofBL2 + " " + "概率：" +"0" + GLofBL2); 
		  	}
	  	}
	  };
	 

}

